package xushuo.dao.entity.weixin.user;

import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.Date;

/**
 * Create by zhangpe0312@qq.com on 2018/2/2.
 *
 * 通过微信小程序电话号码
 */
@Entity
@Table(name = "getPhoneNum")
public class GetPhoneNum implements GetInfo{

    private String id;
    private String phoneNumber;
    private String purePhoneNumber;
    private String countryCode;
    private Date getTime;

    private UserLoginInfo userLoginInfo;

    public GetPhoneNum(String phoneNumber, String purePhoneNumber, String countryCode) {
        this.phoneNumber = phoneNumber;
        this.purePhoneNumber = purePhoneNumber;
        this.countryCode = countryCode;
        this.getTime = new Date();
    }

    @Id
    @Column(name = "id", nullable = false, unique = true)
    @GenericGenerator(name = "generator", strategy = "uuid")
    @GeneratedValue(generator = "generator")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    /**
     * 手机号码唯一i，作为唯一判断
     * @return 用户手机号码
     */
    @Column(name = "phoneNumber", nullable = false, length = 20,unique = true)
    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    @Column(name = "purePhoneNumber", nullable = false, length = 32)
    public String getPurePhoneNumber() {
        return purePhoneNumber;
    }

    public void setPurePhoneNumber(String purePhoneNumber) {
        this.purePhoneNumber = purePhoneNumber;
    }

    @Column(name = "countryCode", nullable = false, length = 32)
    public String getCountryCode() {
        return countryCode;
    }

    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

    @Column(name = "getTime",length = 19,updatable=false)
    @Temporal(TemporalType.TIMESTAMP)
    public Date getGetTime() {
        return getTime;
    }

    public void setGetTime(Date getTime) {
        this.getTime = getTime;
    }

    //关联表UserLoginInfo 为维护这个信息的对象
    @OneToOne(mappedBy = "phoneNum")
    public UserLoginInfo getUserLoginInfo() {
        return userLoginInfo;
    }

    public void setUserLoginInfo(UserLoginInfo userLoginInfo) {
        this.userLoginInfo = userLoginInfo;
    }
}
